/*
 * @Date: 2023-05-25 12:07:11
 * @LastEditors: Penn.ji
 * @LastEditTime: 2024-05-29 22:04:08
 * @FilePath: \chrome-tools\mini-toolbox-gitee\vue.config.js
 */
const path = require('path')
const CONFIG = require('./package.json')
const APP_NAME = CONFIG.name
const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const FileManagerPlugin = require('filemanager-webpack-plugin')
const devServerProxy = require('./devServerProxy')
const dayjs = require('dayjs')
function resolve(dir) {
  return path.join(__dirname, dir)
}
const port = 5966 // dev port
module.exports = {
  // publicPath: process.env.SYS_ENV !== 'production' ? ('/' + APP_KEY) : '/',
  publicPath: './',
  outputDir: path.resolve(__dirname, `./${APP_NAME}`),
  chainWebpack: config => {
    config.plugins.delete('preload')
    // 移除 prefetch 插件
    config.plugins.delete('prefetch')
    config.resolve.alias
      .set('components', resolve('src/components'))
      .set('views', resolve('src/views'))
  },
  configureWebpack: {
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      new FileManagerPlugin({ // 初始化 filemanager-webpack-plugin 插件实例
        onEnd: {
          delete: [ // 首先需要删除项目根目录下的.zip
            `./${APP_NAME}.zip`
          ],
          // mkdir: ['.zip'], // 需要先创建.zip文件夹，否则压缩会报找不到路径
          archive: [ // 然后我们选择dist文件夹将之打包成.zip并放在根目录
            // { source: `./${APP_NAME}`, destination: `.zip/${APP_NAME}_${dayjs().format('YYYYMMDDHHmm')}.zip` }
            { source: `./${APP_NAME}`, destination: `./${APP_NAME}.zip` }
          ]
        }
      })
    ]
  },
  devServer: {
    port: port,
    // 跨域
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    proxy: {
      ...devServerProxy
    }
  },
  runtimeCompiler: true,
  transpileDependencies: []
}
